<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>原型对象</title>
</head>

<body>
  <script>
    // ============================== 原型对象 ==============================

    function Person(name,age) {
      this.name = name
      this.age = age
      // this.sayHi = function(){
      //   console.log('hi') 
      // }
    }
    Person.prototype.sayHi = function(){
      console.log('hello') 
    }
    // console.dir(Person)
    console.dir(Person.prototype) //{constructor：f()}
    
    // 实例化
    const zs = new Person('张三', 18)
    const ls = new Person('李四', 19)
    console.log(zs)
    console.log(ls)
    zs.sayHi()
    ls.sayHi()
    console.log(zs.sayHi === ls.sayHi)  //true 都是从Person.prototype 原型对象上访问到

    // 思考题
    const arr = [10,20,30]
    // 问题：arr 从哪里得到了push 方法来使用？  在Array.prototype
    // arr 是实例对象，本质是new Array
    arr.push(40)
    console.log(Array.prototype)
    
  </script>
</body>

</html>